package com.zzyl.controller;

import com.aliyun.iot20180120.models.QueryDeviceDetailRequest;
import com.aliyun.iot20180120.models.QueryDevicePropertyStatusRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedRequest;
import com.aliyun.iot20180120.models.QueryThingModelPublishedResponse;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeviceDto;
import com.zzyl.dto.DevicePageQueryDto;
import com.zzyl.service.DeviceService;
import com.zzyl.vo.DeviceVo;
import com.zzyl.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/iot")
@Api(tags = "管理端 - 物联网iot相关接口")
public class DeviceController {
    @Autowired
    private DeviceService deviceService;

    @PostMapping("/syncProductList")
    @ApiOperation(value = "从物联网平台同步产品列表")
    public ResponseResult<Void> syncProductList() {
        deviceService.syncProductList();
        return ResponseResult.success();
    }
    @ApiOperation("产品的列表展示")
    @GetMapping("/allProduct")
    public ResponseResult<List<ProductVo>> allProduct(){
        return ResponseResult.success( deviceService.allProduct());
    }
    @PostMapping("/RegisterDevice")
    @ApiOperation("注册设备")
    public ResponseResult<Void> registerDevice(@RequestBody DeviceDto deviceDto){
        return ResponseResult.success(deviceService.registerDevice(deviceDto)) ;
    }
    //分页查询
    @ApiOperation("产品分页查询")
    @GetMapping("/pageQueryDevice")
   public ResponseResult<PageResponse<DeviceVo>>pageQueryDevice(DevicePageQueryDto devicePageQueryDto){
        PageResponse<DeviceVo> deviceVoPageResponse=deviceService.pageQueryDevice(devicePageQueryDto);
        return ResponseResult.success(deviceVoPageResponse);
   }
   //条件查询
    @ApiOperation("条件查询")
    @PostMapping("/QueryDeviceDetail")
  public ResponseResult<DeviceVo>queryDeviceDetail(@RequestBody QueryDeviceDetailRequest request){
   return deviceService.queryDeviceDetail(request);
  }
  @ApiOperation("物模型运行状态已发布的产品")
  @PostMapping("/QueryThingModelPublished")
public ResponseResult QueryThingModelPublished(@RequestBody QueryThingModelPublishedRequest request){
        return deviceService.QueryThingModelPublished(request);
}
@ApiOperation("设备的物模型运行状态")
@PostMapping("/QueryDevicePropertyStatus")
private ResponseResult queryDevicePropertyStatus(@RequestBody QueryDevicePropertyStatusRequest request){
        return deviceService.QueryDevicePropertyStatus(request);
}
}